package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.Reports;
import com.ypd.shop.service.IReportsService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 举报店铺Controller
 * 
 * @author lin
 * @date 2024-12-12
 */

@RestController
@RequestMapping("/shop/reports")
@Api(tags = "举报店铺Controller")
public class ReportsController extends BaseController
{
    @Autowired
    private IReportsService reportsService;

    /**
     * 查询举报店铺列表
     */
    @ApiOperation("查询举报店铺列表")
    //@PreAuthorize("@ss.hasPermi('shop:reports:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reports reports)
    {
        startPage();
        List<Reports> list = reportsService.selectReportsList(reports);
        return getDataTable(list);
    }

    /**
     * 导出举报店铺列表
     */
    @ApiOperation("导出举报店铺列表")
    //@PreAuthorize("@ss.hasPermi('shop:reports:export')")
    @Log(title = "举报店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reports reports)
    {
        List<Reports> list = reportsService.selectReportsList(reports);
        ExcelUtil<Reports> util = new ExcelUtil<Reports>(Reports.class);
        util.exportExcel(response, list, "举报店铺数据");
    }

    /**
     * 获取举报店铺详细信息
     */
    @ApiOperation("获取举报店铺详细信息")
    //@PreAuthorize("@ss.hasPermi('shop:reports:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(reportsService.selectReportsByReportId(reportId));
    }

    /**
     * 新增举报店铺
     */
    @ApiOperation("新增举报店铺")
    //@PreAuthorize("@ss.hasPermi('shop:reports:add')")
    @Log(title = "举报店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reports reports)
    {
        return toAjax(reportsService.insertReports(reports));
    }

    /**
     * 修改举报店铺
     */
    @ApiOperation("修改举报店铺")
    //@PreAuthorize("@ss.hasPermi('shop:reports:edit')")
    @Log(title = "举报店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reports reports)
    {
        return toAjax(reportsService.updateReports(reports));
    }

    /**
     * 删除举报店铺
     */
    @ApiOperation("删除举报店铺")
    //@PreAuthorize("@ss.hasPermi('shop:reports:remove')")
    @Log(title = "举报店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(reportsService.deleteReportsByReportIds(reportIds));
    }
    /**
     * 管理员处理举报信息
     */
    @ApiOperation("管理员处理举报信息")
    //@PreAuthorize("@ss.hasPermi('shop:reports:edit')")
    @Log(title = "举报店铺", businessType = BusinessType.UPDATE)
    @PutMapping("/admin")
    public AjaxResult handle(@RequestBody Reports reports)
    {
        //todo
        //总觉得这里要和信箱功能相结合,或者微聊功能相结合
        //判断操作类型,如果是0表示不进行操作.仅仅是给举报人返回证据不成立
        int operation = Integer.parseInt(reports.getParams().get("operation").toString());
        if(operation == 0){

        }
        //如果是1,2进行操作.同时需要给被举报人传递信息
        return toAjax(reportsService.updateReports(reports));
    }
}
